package org.fastsyncer.framework.connector;

import org.fastsyncer.common.constant.ConnectorConstant;
import org.fastsyncer.common.entity.DatabaseConfig;
import org.fastsyncer.common.entity.LdapConfig;
import org.fastsyncer.common.entity.BaseInfo;
import org.fastsyncer.connector.database.DatabaseConnector;
import org.fastsyncer.connector.framework.ConnectorFactory;
import org.fastsyncer.connector.ldap.LdapConnector;

public class ConnectorService {

	private static final ConnectorService instance = new ConnectorService();

	private ConnectorService() {
	}

	public static ConnectorService getInstance() {
		return instance;
	}

	/**
	 * 获取连接器配置详细信息
	 * @Title: getBaseInfoConnector 
	 * @Description: 获取连接器配置详细信息
	 * @param connector 连接器类型
	 * @param config 连接器配置
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws ClassNotFoundException
	 * @return: BaseInfo 包括连接器的配置、元信息、总条数
	 */
	public BaseInfo getBaseInfoConnector(String connector, Object config)
			throws InstantiationException, IllegalAccessException, ClassNotFoundException {
		BaseInfo baseInfo = null;
		switch (connector) {
		case ConnectorConstant.DB_CONNECTOR:
			DatabaseConnector dbConnector = (DatabaseConnector) ConnectorFactory.getInstance(ConnectorConstant.DB_CONNECTOR);
			baseInfo = dbConnector.getBaseInfoConnector((DatabaseConfig) config);
			break;
		case ConnectorConstant.LDAP_CONNECTOR:
			LdapConnector ldapConnector = (LdapConnector) ConnectorFactory.getInstance(ConnectorConstant.LDAP_CONNECTOR);
			baseInfo = ldapConnector.getBaseInfoConnector((LdapConfig) config);
			break;
		default:
			break;
		}
		return baseInfo;
	}

}
